<div class="tab-pane fade" id="detailTab">
    <foreach name="row.airway_detail" item="airwayDetail">
        <div>
            <div class="form-group">
                <label class="control-label col-sm-3">途经地名称:</label>
                <div class="col-sm-7">
                    <input type="text" class="form-control" name="_name[]" value="{$airwayDetail.name}" placeholder="请输入途经地名称">
                </div>
                <button type="button" class="btn btn-primary" style="margin-left: 10px;" onclick="delName(this)">删除</button>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">到达时间:</label>
                <div class="col-sm-7">
                    <div class="input-group date" id="reach_date_num">
                        <input type='text' value="{$airwayDetail.reach_date|date="Y-m-d H:i",###}" name="_reach_date[]" class="form-control" data-date-format="yyyy-mm-dd hh:ii" />
                        <div class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </div>
                    </div>
                </div>
            </div>
            <hr />
        </div>
    </foreach>
    <button type="button" id="btn_prop" class="btn btn-primary pull-right">添加途经地</button>
</div>

<script type="text/javascript">

    $(function () {
        $("#btn_prop").bind("click",addName);
        changeItem();
    });

    function addName() {
        $("#btn_prop").before($("#prop_template").html());
        changeItem();
    }

    function delName(obj) {
        $(obj).parent().parent().remove();
        changeItem();
    }
    
    function changeItem() {
        var $divs = $("#detailTab").children("div");
        var len = $divs.length;
        console.log(len);
        for(var i=0;i<len;i++) {
            var dateId = "reach_date_"+i;
            $divs.eq(i).find("[id^='reach_date_']").attr("id",dateId);
            $("#"+dateId).datetimepicker({
                format: "yyyy-mm-dd hh:ii",
                language: "ch",
                pickDate: true,
                pickTime: false,
                autoclose: true,
                minView: 0
            });
        }
    }
</script>